package com.varton.session;

import com.varton.MapperProxy;
import com.varton.configuration.Configuration;
import com.varton.executor.Executor;

import java.lang.reflect.Proxy;

public class MySqlSession {
    private Configuration configuration;
    private Executor executor;

    public MySqlSession(Configuration configuration, Executor executor) {
        this.configuration = configuration;
        this.executor = executor;
    }

    public <T> T getMapper(Class<T> mapperClass) {
        return (T) Proxy.newProxyInstance(mapperClass.getClassLoader(),new Class[]{mapperClass},new MapperProxy<T>(this,mapperClass));
    }

    public String lookUpSql(String id) {
        return configuration.getSql(id);
    }

    public <T> T selectOne(String statment, Object[] prama) {
        return executor.execute(statment,prama);
    }
}
